package com.new_wear.project.article.article.service.impl;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.new_wear.project.article.article.mapper.CstArticleMapper;
import com.new_wear.project.article.article.domain.CstArticle;
import com.new_wear.project.article.article.service.ICstArticleService;
import com.new_wear.common.utils.text.Convert;

/**
 * 文章Service业务层处理
 * 
 * @author new
 * @date 2019-12-30
 */
@Service
public class CstArticleServiceImpl implements ICstArticleService 
{
    @Autowired
    private CstArticleMapper cstArticleMapper;

    /**
     * 查询文章
     * 
     * @param id 文章ID
     * @return 文章
     */
    @Override
    public CstArticle selectCstArticleById(Integer id)
    {
        return cstArticleMapper.selectCstArticleById(id);
    }

    /**
     * 查询文章列表
     * 
     * @param cstArticle 文章
     * @return 文章
     */
    @Override
    public List<CstArticle> selectCstArticleList(CstArticle cstArticle)
    {
        return cstArticleMapper.selectCstArticleList(cstArticle);
    }

    /**
     * 新增文章
     * 
     * @param cstArticle 文章
     * @return 结果
     */
    @Override
    public int insertCstArticle(CstArticle cstArticle)
    {
        return cstArticleMapper.insertCstArticle(cstArticle);
    }

    /**
     * 修改文章
     * 
     * @param cstArticle 文章
     * @return 结果
     */
    @Override
    public int updateCstArticle(CstArticle cstArticle)
    {
        return cstArticleMapper.updateCstArticle(cstArticle);
    }

    /**
     * 删除文章对象
     * 
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteCstArticleByIds(String ids)
    {
        return cstArticleMapper.deleteCstArticleByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除文章信息
     * 
     * @param id 文章ID
     * @return 结果
     */
    @Override
    public int deleteCstArticleById(Integer id)
    {
        return cstArticleMapper.deleteCstArticleById(id);
    }

    @Override
    public int publishCstArticle(Integer id) {
        CstArticle cstArticle = cstArticleMapper.selectCstArticleById(id);
        if (cstArticle.getIsPublish()==0){
            cstArticle.setIsPublish(1);
        }else {
            cstArticle.setIsPublish(0);
        }
        return cstArticleMapper.updateCstArticle(cstArticle);
    }

}
